package com.toune.villager.adapter

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.viewpager2.adapter.FragmentStateAdapter

class MainVPAdapter(fragments: MutableList<Fragment>,
                    fragmentActivity: FragmentActivity
): FragmentStateAdapter(fragmentActivity) {
    var fragments:MutableList<Fragment> = fragments
    override fun getItemCount(): Int {
        return fragments.size
    }

    fun addFragment(fragment: Fragment){
        fragments.add(fragment)
        notifyDataSetChanged()
    }
    fun removeFragment(fragment: Fragment){
        fragments.remove(fragment)
        notifyDataSetChanged()
    }
    override fun createFragment(position: Int): Fragment {
        return fragments[position]
    }
}
